package com.meituan.catering.management.shop.biz.model.converter;

import com.meituan.catering.management.shop.api.http.model.request.SearchShopHttpRequest;
import com.meituan.catering.management.shop.biz.model.ShopBO;
import com.meituan.catering.management.shop.biz.model.common.PageBO;
import com.meituan.catering.management.shop.biz.model.enumeration.BusinessTypeEnum;
import com.meituan.catering.management.shop.biz.model.enumeration.DescribableEnum;
import com.meituan.catering.management.shop.biz.model.enumeration.EnabledEnum;
import com.meituan.catering.management.shop.biz.model.enumeration.ManagementTypeEnum;
import com.meituan.catering.management.shop.dao.model.ShopDO;
import com.meituan.catering.management.shop.dao.model.request.SearchShopDataRequest;
import org.apache.commons.lang3.StringUtils;


import java.text.MessageFormat;
import java.util.List;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toList;

/**
 * @Author:ale
 * @Date 2022/4/22 17:05
 * @Version 1.0
 */
public abstract class ShopBOConverter {


    public static ShopBO fromDO(ShopDO shopDO) {
        if (shopDO == null) {
            return null;
        }
        ShopBO shopBO = new ShopBO();
        //Convert - Base
        shopBO.setId(shopDO.getId());
        shopBO.setTenantId(shopDO.getTenantId());
        shopBO.setSuperiorId(shopDO.getSuperiorId());
        //Convert - Shop
        shopBO.setBusinessNo(shopDO.getBusinessNo());
        shopBO.setName(shopDO.getName());
        shopBO.getContact().setContactCellphone(shopDO.getContactCellphone());
        shopBO.getContact().setContactTelephone(shopDO.getContactTelephone());
        shopBO.getContact().setContactName(shopDO.getContactName());
        shopBO.getContact().setContactAddress(shopDO.getContactAddress());
        shopBO.setBusinessType(DescribableEnum.getByCode(BusinessTypeEnum.class,shopDO.getBusinessType()));
        shopBO.setManagementType(DescribableEnum.getByCode(ManagementTypeEnum.class, shopDO.getManagementType()));
        shopBO.getOpeningHours().setOpeningHoursStart(shopDO.getOpeningHoursStart());
        shopBO.getOpeningHours().setOpeningHoursEnd(shopDO.getOpeningHoursEnd());
        shopBO.setBusinessArea(shopDO.getBusinessArea());
        shopBO.setComment(shopDO.getComment());
        shopBO.setEnabled(DescribableEnum.getByCode(EnabledEnum.class,shopDO.getEnabled()));
        return shopBO;
    }

    public static PageBO<ShopBO> buildPageBO(SearchShopHttpRequest request, int totalCount) {
        int totalPageCount = (totalCount + request.getPageSize() - 1) / request.getPageSize();
        PageBO<ShopBO> shopPageBO = new PageBO<>();
        shopPageBO.setPageIndex(request.getPageIndex());
        shopPageBO.setPageSize(request.getPageSize());
        shopPageBO.setTotalCount(totalCount);
        shopPageBO.setTotalPageCount(totalPageCount);
        return shopPageBO;
    }



}
